package cn.stylefeng.guns.modular.manager.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.FlowCommissionManagement;
import cn.stylefeng.guns.modular.manager.entity.FlowStoreRegionPrice;
import cn.stylefeng.guns.modular.manager.model.params.FlowCommissionManagementParam;
import cn.stylefeng.guns.modular.manager.model.params.FlowStoreRegionPriceParam;
import cn.stylefeng.guns.modular.manager.service.FlowCommissionManagementService;
import cn.stylefeng.guns.modular.manager.service.FlowStoreRegionPriceService;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/flowCommissionManagement")
public class FlowCommissionManagementController {

    private String PREFIX = "/manager/flowCommissionManagement";
    private String PREFIX1 = "/manager/flowGetMoney";


    @Autowired
    private FlowCommissionManagementService flowCommissionManagementService;
    /**
     * 跳转到主页面
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/flowCommissionManagement.html";
    }

    @RequestMapping("/getMoney")
    public String index1() {
        return PREFIX1 + "/flowGetMoney.html";
    }
    /**
     * 新增页面
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/flowCommissionManagement_add.html";
    }

    @RequestMapping("/auth")
    public String auth() {
        return "/manager/flowAuth" + "/auth.html";
    }
    /**
     * 编辑页面
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/flowCommissionManagement_edit.html";
    }

    /**
     * 新增接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(FlowCommissionManagementParam flowCommissionManagementParam) {
        this.flowCommissionManagementService.add(flowCommissionManagementParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(FlowCommissionManagementParam flowCommissionManagementParam) {
        this.flowCommissionManagementService.update(flowCommissionManagementParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(FlowCommissionManagementParam flowCommissionManagementParam) {
        this.flowCommissionManagementService.delete(flowCommissionManagementParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(FlowCommissionManagementParam flowCommissionManagementParam) {
        FlowCommissionManagement detail = this.flowCommissionManagementService.getById(flowCommissionManagementParam.getCommissionId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(FlowCommissionManagementParam flowCommissionManagementParam) {
        return this.flowCommissionManagementService.findPageBySpec(flowCommissionManagementParam);
    }


    @ResponseBody
    @RequestMapping("/getMoneyList")
    public LayuiPageInfo getMoneyList(FlowCommissionManagementParam flowCommissionManagementParam) {
        flowCommissionManagementParam.setOnlySign(3l);

        return this.flowCommissionManagementService.findPageBySpec(flowCommissionManagementParam);
    }
    /**
     * 佣金汇总
     * @param flowCommissionManagementParam
     * @return
     */
    @ResponseBody
    @RequestMapping("/getOnly")
    public FlowCommissionManagement getOnly(FlowCommissionManagementParam flowCommissionManagementParam) {
        QueryWrapper<FlowCommissionManagement> flowCommissionManagementQueryWrapper = new QueryWrapper<>();
        flowCommissionManagementQueryWrapper.eq("user_id",flowCommissionManagementParam.getUserId());
        flowCommissionManagementQueryWrapper.eq("only_sign",1l);
        flowCommissionManagementQueryWrapper.last("limit 1");
        FlowCommissionManagement flowCommissionManagement=this.flowCommissionManagementService.getOne(flowCommissionManagementQueryWrapper);
        return flowCommissionManagement;
    }

    /**
     * 获取每笔订单佣金记录
     * @param flowCommissionManagementParam
     * @return
     */
    @ResponseBody
    @RequestMapping("/getFlowCommissionManagementList")
    public List<FlowCommissionManagement> getFlowCommissionManagementList(FlowCommissionManagementParam flowCommissionManagementParam) {
        QueryWrapper<FlowCommissionManagement> flowCommissionManagementQueryWrapper = new QueryWrapper<>();
        flowCommissionManagementQueryWrapper.eq("user_id",flowCommissionManagementParam.getUserId());
        flowCommissionManagementQueryWrapper.eq("only_sign",0l);
        flowCommissionManagementQueryWrapper.last("limit 1");
        List<FlowCommissionManagement> list=this.flowCommissionManagementService.list(flowCommissionManagementQueryWrapper);
        return list;
    }

    /**
     * 提现申请记录
     * @param flowCommissionManagementParam
     * @return
     */
    @ResponseBody
    @RequestMapping("/getApplyDraw")
    public List<FlowCommissionManagement> getApplyDraw(FlowCommissionManagementParam flowCommissionManagementParam) {
        QueryWrapper<FlowCommissionManagement> flowCommissionManagementQueryWrapper = new QueryWrapper<>();
        flowCommissionManagementQueryWrapper.eq("user_id",flowCommissionManagementParam.getUserId());
        flowCommissionManagementQueryWrapper.eq("only_sign",2l);
        flowCommissionManagementQueryWrapper.last("limit 1");
        List<FlowCommissionManagement> list=this.flowCommissionManagementService.list(flowCommissionManagementQueryWrapper);
        return list;
    }
}
